//
//  XL_NetManager.m
//  OnePointDemo
//
//  Created by 薛磊 on 2018/7/9.
//  Copyright © 2018年 XL. All rights reserved.
//

#import "XL_NetManager.h"
#import <AFNetworking/AFNetworking.h>

@implementation XL_NetManager


+(AFHTTPSessionManager *)shareManager{
    
    static AFHTTPSessionManager * manager = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manager = [AFHTTPSessionManager manager];
        manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
        manager.requestSerializer.timeoutInterval = 20;
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",@"text/json",@"text/javascript",@"text/plain",nil];
        
    });
    
    return manager;
    
}
+ (void)POST:(NSString *)path params:(NSMutableDictionary *)params completionHandle:(void (^)(id, NSError *))completionHandle{
    
    [[self shareManager] POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (completionHandle) {
            completionHandle(responseObject, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (completionHandle) {
            completionHandle(nil, error);
        }
    }];
}
+ (void)GET:(NSString *)path params:(NSMutableDictionary *)params completionHandle:(void (^)(id, NSError *))completionHandle{
    
    [[self shareManager] GET:path parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (completionHandle) {
            completionHandle(responseObject, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (completionHandle) {
            completionHandle(nil, error);
        }
        
    }];
}





@end
